package bastanteo.servlet;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bastanteo.modelo.GrupoBastanteo;
import bastanteo.negocio.GrupoNegocio;

/**
 * Servlet implementation class ProductosBuscarServlet
 */
@WebServlet("/GrupoBastanteoServlet")
public class GrupoBastanteoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public GrupoBastanteoServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
/*		System.out.println(request.getParameter("txtConsulta"));
		if(request.getParameter("txtConsulta")==null){
			try {
				String codBastanteo = request.getParameter("txtCodigo");
				String codGrupo = request.getParameter("lstGrupo");
				String codpoder = request.getParameter("lstPoderes");
				String forma = request.getParameter("lstForma");
				String combinacion = request.getParameter("txtCombinacion");
				String importe = request.getParameter("txtImporte");
				String fecVigencia = request.getParameter("txtVigencia");
				String existe;
				System.out.println("1 "+codGrupo);
				System.out.println("2 "+codpoder);
				System.out.println("3 "+fecVigencia);
				BastanteoNegocio bn = new BastanteoNegocio();
				existe=bn.BastantearPoderes(codBastanteo, forma, combinacion, Double.parseDouble(importe), fecVigencia, codpoder, codGrupo);
				
				request.setAttribute("bastanteo", "1");
				request.setAttribute("existe", existe);
				
	
				//rd.forward(request, response);
			} catch (Exception e) {
				request.setAttribute("bastanteo", "0");
				System.out.println(e.getMessage());
			}
			RequestDispatcher rd = request.getRequestDispatcher("BastantearPoderes.jsp");
			rd.forward(request, response);
		}else{
*/		
			String codcli = request.getParameter("txtcod");
			
			try {
				GrupoNegocio gn = new GrupoNegocio();
				Collection<GrupoBastanteo> cgb = gn.listar_x_cli(codcli);
				
				//ProductosNegocio negocio = new ProductosNegocio();
				request.setAttribute("cgbastanteo", cgb);
			} catch (Exception e) {
				request.setAttribute("cgbastanteo", null);
				System.out.println(e.getMessage());
			}	
			RequestDispatcher rd = request.getRequestDispatcher("consultargrupobastanteo.jsp");
			rd.forward(request, response);
//		}
	}

}
